<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml"><!-- InstanceBegin template="/Templates/TemplateAD.dwt" codeOutsideHTMLIsLocked="false" -->
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<!-- InstanceBeginEditable name="doctitle" -->
<title>CircleU - Administrator</title>
<?php
 	session_start(); 
	///////////////////////// For test
	$_SESSION["login"] = true; $_SESSION["AdminID"]=2011;
	/////////////////////////
	if( !$_SESSION["login"] || !isset($_SESSION["AdminID"]))header('Location: error_page.php');
	if(!isset($_GET["CID"])){
		header('Location: error_page.php');
		//echo "No CID!!!";
	}
	include("db_util.php");
	putenv("ORACLE_HOME=/usr/local/libexec/oracle/app/oracle/product/11.2.0/client_1");
	$connection=DbConnect();
	if(!$connection)
		echo "DisConnected!<br>";
	$query='SELECT * FROM Administrator where AID=' . $_SESSION["AdminID"]; 
	$statement = oci_parse($connection, $query);
	oci_execute($statement);
	$admin = oci_fetch_array($statement, OCI_ASSOC+OCI_RETURN_NULLS);
	oci_free_statement($statement);
?>
<!-- InstanceEndEditable -->
<style type="text/css">
<!--

a:link   {
text-decoration:   none;
}
a:visited   {
text-decoration:   none;
}
a:hover   {
text-decoration:   underline;
} 
.try {
	background-color: #FFFFFF;
	position: relative;
	z-index: auto;
	visibility: visible;
	clip: rect(auto,auto,auto,auto);
	width: auto;
	height: 76px;
}
.copyright {
	position: absolute;
	left: 236px;
	top: 600px;
	font-size: large;
	height: 22px;
}
.LayerImg {
	left: auto;
}
.CircleU {
	font-family: "Comic Sans MS";
	font-size: xx-large;
	font-weight: bold;
	position: relative;
	left: 20px;
	top: auto;
	height: auto;
	width: auto;
	visibility: visible;
	background-position: left;
	color: #3333FF;
}
#Title1 {
	position:absolute;
	width:1096px;
	height:60px;
	z-index:2;
	left: 9px;
	top: 6px;
}



}

#Dwt01 {
	position:absolute;
	width:1092px;
	height:500px;
	right: 9px;
	top: 80px;
}
#LeftLayer {
	position:absolute;
	width:200px;
	height:500px;
	z-index:3;
	left: 11px;
	top: 77px;
	background-color: #FF6600;
}
#EditR1 {
	position:absolute;
	width:878px;
	height:500px;
	z-index:4;
	left: 221px;
	top: 77px;
}
.STYLE3 {color: #0000CC}
#Layer1 {
	position:absolute;
	width:181px;
	height:217px;
	z-index:1;
	left: 2px;
	top: 2px;
}
.STYLE4 {
	font-size: 18px;
	font-weight: bold;
}
-->
</style><script type="text/JavaScript">
<!--
function MM_findObj(n, d) { //v4.01
  var p,i,x;  if(!d) d=document; if((p=n.indexOf("?"))>0&&parent.frames.length) {
    d=parent.frames[n.substring(p+1)].document; n=n.substring(0,p);}
  if(!(x=d[n])&&d.all) x=d.all[n]; for (i=0;!x&&i<d.forms.length;i++) x=d.forms[i][n];
  for(i=0;!x&&d.layers&&i<d.layers.length;i++) x=MM_findObj(n,d.layers[i].document);
  if(!x && d.getElementById) x=d.getElementById(n); return x;
}

function MM_showHideLayers() { //v6.0
  var i,p,v,obj,args=MM_showHideLayers.arguments;
  for (i=0; i<(args.length-2); i+=3) if ((obj=MM_findObj(args[i]))!=null) { v=args[i+2];
    if (obj.style) { obj=obj.style; v=(v=='show')?'visible':(v=='hide')?'hidden':v; }
    obj.visibility=v; }
}
//-->
</script>
<!-- InstanceBeginEditable name="head" --><!-- InstanceEndEditable -->
</head>

<body>
<center>
  <div id="Title1">
    <table width="1092" height="59" bgcolor="#FF6600">
      <tr>
        <td rowspan="2" class="CircleU"><div align="left"><?php echo "<a href=\"index.php\">"; ?> <span class="STYLE3">CircleU</a></span></div></td>
        <td width="128"><?php echo "<a href=\"index.php\">"; ?> </a></td>
        <td width="111"><div align="right"><?php echo "<a href=\"SignOut.php\">"; ?>Sign Out </a></div></td>
        <td width="120"><div align="center"><?php echo "<a href=\"ContactUs.php\">"; ?>Contact Us</a></div></td>
      </tr>
      <tr>
        <td><form id="form2" name="form2" method="post" <?php echo "action=\"AdminAdvancedSearch.php\""; ?>>
          <label>
            <input type="submit" name="AdvancedSearch" value="Advanced Search" />
          </label>
        </form>
        </td>
        <td colspan="2"><form id="form1" name="form1" method="post" <?php echo "action=\"AdminSearchResult.php\""; ?>>
          <label>
            <input type="text" name="search_text" />
          </label>
          <label>
          <input type="submit" name="Search" value="Search" />
          </label>
        </form>        </td>
      </tr>
    </table>
  </div>
  <div class="copyright">
<p>Copyright @ 2011 CircleU built in University of Florida. All right reserved&#13;</p>

</div>
  <div id="LeftLayer">
    <div id="Layer1">
	 <h3>Welcome, <?php echo $admin["FIRST_NAME"];?>!</h3>
      <table width="180" height="73" border="1">
	    <tr>
		  <td colspan="2" align="center" valign="middle">
			  <?php echo "<img src=\"". $admin["PROFILE_PIC"] . "\" width=\"180\" height=\"120\" />";?>
		  </td>
		</tr>
        <tr>
          <td width="76" height="34">Admin ID: </td>
          <td width="105"><?php echo $_SESSION["AdminID"]; ?></td>
        </tr>
        <tr>
          <td height="31">Name: </td>
          <td><?php echo $admin["FIRST_NAME"] . " " . $admin["LAST_NAME"];?></td>
        </tr>
      </table>
	<?php 
		echo "<p><a href=\"AdminHome.php\">Main Menu</a></p>";
		oci_close($connection);
	?>
    </div>
    
  
  </div>
  <div id="EditR1"><!-- InstanceBeginEditable name="EditRegion3" -->
    <div id="Layer3">
	<?php
	$cid = $_GET["CID"];
	$con = DbConnect();
	$course = get_course_info_with_con($con, $cid);
	if(isset($_POST["delete_course"])){ // add course
		delete_course_with_con($con, $cid);
	}
	?>
	<h2>
   		<?php echo $course["CID"] . ": " . $course["CNAME"];?>
	</h2>
	<h3><?php echo "Instructor: " . $course["INSTRUCTOR"] . "(" . $course["SEMESTER"] . ")"; ?></h3>
	<form  id="form2" name="form2" method="post" action="AdminCourseHome.php?CID=<?php echo $course["CID"]; ?>"> 
	<?php echo "<input type=\"submit\" name=\"edit_course\" 
			value=\"Edit Course\" onclick=\"location.href='AdminEditCourse.php?CID=". $cid . "'\" />
			<input type=\"submit\" name=\"delete_course\" value=\"Delete Course Permanently\"/>";?>
	 </form>
    <table width="850" border="0">
      <tr>
        <td width= "150" style="text-align:right">Time: </td>
        <td style="text-align:left"><?php echo $course["LECTURE_TIME"]; ?></td>
		<td style="text-align:right">Location: </td>
        <td><?php echo $course["LOCATION"]; ?></td>
      </tr>
	  <tr>
        <td style="text-align:right">Textbook: </td>
        <td colspan="3"><?php echo $course["TEXTBOOK"]; ?></td>
      </tr>
      <tr>
        <td style="text-align:right">TAs: </td>
        <td colspan="3"><?php echo $course["TA"]; ?></td>
      </tr>
      <tr>
        <td style="text-align:right">Office Hours: </td>
        <td colspan="3"><?php echo $course["OFFICE_HOURS"]; ?></td>
      </tr>
      <tr>
        <td style="text-align:right" valign="top">Description: </td>
        <td colspan="3"><?php echo $course["DESCRIPTION"]; ?></td>
      </tr>
	  <tr>
	  	<td colspan="4"><hr /></td>
	  </tr>
    </table>
  </div>
    <div id="Layer4"> 
	<form id="form1" name="form1" method="post" action="AdminCourseHome.php?CID=<?php echo $cid;?>">
    <table width="850" border="0">
	<?php
		// fetch all pages from DB
		$posts = get_posts_with_con($con, $cid);
		
		// deciding how many pages in total and which page to show.
		$max_post_per_page = 3;
		$num_of_posts = count($posts);
		$max_page = ceil($num_of_posts / $max_post_per_page);
		if(!isset($_GET["post_page"])||$_GET["post_page"]<1||$_GET["post_page"]>$max_page)
			$post_page=1;
		else
			$post_page=$_GET["post_page"];
		//----------------
	?>
      <tr>
        <td>Latest Post: </td>
		<td>&nbsp;</td>
		<td style="text-align:right">
		<?php
			// Printing "next page", "previous page" buttons.
			if($post_page==1) 	echo "<< "; 
			else echo "<a href=\"AdminCourseHome.php?CID=" . $cid . "&post_page=" . ($post_page-1). "\"><<</a> ";
			if($post_page==$max_page)	echo ">> ";
			else	echo"<a href=\"AdminCourseHome.php?CID=" . $cid . "&post_page=" . ($post_page+1). "\">>></a> ";
		?></td>
      </tr>
	  <?php
	  //-------printing posts cutting into pages
		for($i=($max_post_per_page*($post_page-1)); $i<($max_post_per_page*$post_page) && $i<$num_of_posts; $i++){
			echo "<tr>\n";
			echo "<td style=\"text-align:left\"><a href='Personal.php?SID=" . $posts[$i]["AUTHOR"] ."'>" . $posts[$i]["FIRST_NAME"] . "</a> said: </td>";
   			echo "<td style=\"text-align:left\"><a href=\"AdminCoursePost.php?CID=" . $cid . "&CPID=". $posts[$i]["CPID"] . "\">". $posts[$i]["SUBJECT"] . "</a></td>";
			echo "<td style=\"text-align:right\"><a href=\"AdminCoursePost.php?CID=" . $cid . "&CPID=". $posts[$i]["CPID"] . "\">" . $posts[$i]["POST_TIME"] . "</a></td>";
   			echo "</tr>\n";
			echo "<tr>\n";
			echo "<td> &nbsp; </td>";
			echo "<td colspan='2'>" . substr($posts[$i]["CONTENT"], 0, 80) . " ...</td>";
			echo "</tr>\n";
		}		
		//------
		oci_close($con);
	  ?>
	  <tr><td colspan="3"><hr /></td></tr>
    </table>
    </form>
    <p>&nbsp;</p>
  </div>
  <!-- InstanceEndEditable --></div>
</center>
</body>
<!-- InstanceEnd --></html>
